﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ClassInfo.aspx.cs" Inherits="Test.ClassInfo" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="Scripts/jquery-3.3.1.min.js"></script>
    <script>
        //closest:一直向下找
        $(function () {
            $(".del").click(function () {
                var $this = $(this)
                var id = $this.attr("data-id")
                $.ajax({
                    type: "post",
                    url: "./DelClass.ashx",
                    data: { cid: id },
                    success: function (res) {
                        /* $(this).closest("tr").remove():不能这样，this在ajax中，不再是控件*/
                        if (res==1) {
                            $this.closest("tr").remove()
                        }
                        
                    },
                    error: function (response) {
                        console.log(response);
                    }
                })
            })

        });
    </script>
</head>
    
<body>
    <form id="form1" runat="server">
        <a href="ClassInfoAdd.aspx">添加</a>
        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  DataKeyNames="Id" AllowSorting="True" OnRowDeleting="GridView1_RowDeleting"><%--AutoGenerateColumns:是否自动生成字段--%>
                <Columns>
                    <asp:BoundField DataField="Id" HeaderText="编号" />
                    <asp:BoundField DataField="Name" HeaderText="班级" />
                    <asp:BoundField DataField="content" HeaderText="备注" />
                    <asp:HyperLinkField HeaderText="详情" Text="详情"  DataNavigateUrlFields="Id" DataNavigateUrlFormatString="ClassInfoDetial.aspx?id={0}"/>
                    <asp:HyperLinkField HeaderText="修改" Text="修改"  DataNavigateUrlFields="Id" DataNavigateUrlFormatString="ClassInfoUpdate.aspx?id={0}"/>
                    <asp:CommandField ShowDeleteButton="True" />
                    <asp:TemplateField HeaderText="删除">
                        <ItemTemplate>
                            <input id="Button1" type="button" value="button"  class="del"  data-id="<%# Eval("id") %>"/><%--#和=：#--%>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </div>
    </form>
</body>
</html>

